#include "setsizedlg.h"
#include "ui_setsizedlg.h"
#include <QRegExp>

setSizeDlg::setSizeDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::setSizeDlg)
{
    ui->setupUi(this);
    ui->okBtn->setEnabled(false);

    QRegExp regExp("[0-9]{0,5}");
    ui->length->setValidator(new QRegExpValidator(regExp, this));
    ui->width->setValidator(new QRegExpValidator(regExp, this));
}

setSizeDlg::~setSizeDlg()
{
    delete ui;
}


void setSizeDlg::on_length_textChanged(const QString &arg1)
{
    ui->okBtn->setEnabled(ui->length->hasAcceptableInput() &&
                          ui->width->hasAcceptableInput());
}

void setSizeDlg::on_okBtn_clicked()
{
    int length = ui->length->text().toInt();
    int width = ui->width->text().toInt();
    if((length < 65536) && (width < 65536))
    {
        emit setSize(length, width);
    }
    else
    {
        if((length >= 65536))
            emit setSize(65535, width);
        if((width >= 65536))
            emit setSize(length, 65535);
    }
    this->close();
}

void setSizeDlg::on_width_textChanged(const QString &arg1)
{
    ui->okBtn->setEnabled(ui->length->hasAcceptableInput() &&
                          ui->width->hasAcceptableInput());
}
